/*****************************************************************************/
/*                                                                           */
/*    Domino Operation System Kernel Module                                  */
/*                                                                           */
/*    Copyright (C) 2005 Laszlo Arvai                                        */
/*                                                                           */
/*    ------------------------------------------------------------------     */
/*    dosDateTime - Date & Time Functions                                   */
/*****************************************************************************/

#ifndef __dosDateTime_h
#define __dosDateTime_h

///////////////////////////////////////////////////////////////////////////////
// Includes
#include "krnlTypes.h"
#include "krnlString.h"

///////////////////////////////////////////////////////////////////////////////
// Typedefs

// Date&Time
typedef struct _dosDateTime
{
  dosByte Hour;					// 0-23
  dosByte Minute;				// 0-59
  dosByte Second;				// 0-59

  dosWord Year;
  dosByte Month;				// 1-12
  dosByte Day;					// 1-31

  dosByte DayOfWeek;		// 0 - Sunday, 1 - Monday ... 6 - Saturday
} dosDateTime;

// DateTime format
typedef enum
{
	dosDateTimeFormat_YYYYMMDD,
} dosDateTimeFormat;

///////////////////////////////////////////////////////////////////////////////
// Function prototypes
void krnlConvertDayOfWeekToString( dosDateTime* in_date, dosString out_buffer, dosByte in_buffer_length );
dosDWord krnlConvertDateTimeToSeconds( dosDateTime* in_date );
void krnlConvertSecondsToDateTime( dosDateTime* out_datetime, dosDWord in_seconds );

dosStringLength krnlConvertDateToString( dosString out_buffer, dosStringLength in_buffer_length, dosStringLength in_pos, dosDateTime* in_date, dosChar in_separator );
dosStringLength krnlConvertTimeToString( dosString out_buffer, dosStringLength in_buffer_length, dosStringLength in_pos, dosDateTime* in_time );

void krnlStringToDate(dosString in_buffer, dosStringLength in_buffer_length, dosStringLength* inout_pos, dosBool* inout_success, dosDateTime* out_datetime, dosChar in_separator, dosDateTimeFormat in_format);
void krnlStringToTime(dosString in_buffer, dosStringLength in_buffer_length, dosStringLength* inout_pos, dosBool* inout_success, dosDateTime* out_datetime, dosChar in_separator);

void krnlUpdateDayOfWeek( dosDateTime* inout_date );
dosBool krnlIsLeapYear( dosWord in_year );
dosByte krnlGetMonthLength( dosWord in_year, dosByte in_month );
void krnlAddOneSecond( dosDateTime* in_datetime );
dosBool krnlIsEqualDateTime( dosDateTime* in_datetime1, dosDateTime* in_datetime2 );
void krnlNormalizeDateTime( dosDateTime* in_datetime );
dosInt8 krnlCompareDateTime( dosDateTime* in_datetime1, dosDateTime* in_datetime2 );
dosInt8 krnlCompareTime( dosDateTime* in_datetime1, dosDateTime* in_datetime2 );
void krnlSubstractTime( dosDateTime* in_time, dosDateTime* in_time_to_substract );
void krnlSetClockAdjust( dosInt16 in_adjust );
dosInt16 krnlGetClockAdjust(void);

#endif
